<?php
require_once ("../db/connectdatabase.php");
require_once ("../entitys/BankLoan.php");

function getBankLoanSort($idbank, $idloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id', 'loan_id', 'dac_tinh_loan', 'object_dk_loan', 'thu_tuc_loan', 'bankid', 'bankname', 'banklogo', 'datecreate');
	$fcon = array('isavalible' => true, 'bankuse' => true);
	$flike = array('bankid' => $idbank, 'loan_id' => $idloan);
	return $con -> getvalueall($tbl,$fn,$fcon,$flike,'datecreate');
}

function getBankLoan($idloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id', 'loan_id', 'dac_tinh_loan', 'object_dk_loan', 'thu_tuc_loan', 'bankid', 'bankname', 'banklogo', 'datecreate');
	$fcon = array('loan_id' => $idloan, 'isavalible' => true, 'bankuse' => true);
	$flike = array();
	return $con -> getvalueall($tbl,$fn,$fcon,$flike,'datecreate');
}

function insertBankLoan($bankloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id' => ($bankloan -> getID()), 'loan_id' => ($bankloan -> getLoan()), 'dac_tinh_loan' => ($bankloan -> getDacTinh()), 'object_dk_loan' => ($bankloan -> getDieuKien()), 'thu_tuc_loan' => ($bankloan -> getThuTuc()), 'bankid' => ($bankloan -> getBank()), 'bankname' => ($bankloan -> getBankName()), 'banklogo' => ($bankloan -> getBankLogo()), 'datecreate' => ($bankloan -> getDatecreate()));
	return $con -> insert($tbl, $fn);
}

function updateBankLoan($bankloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankid' => ($bankloan -> getBank()), 'dac_tinh_loan' => ($bankloan -> getDacTinh()), 'object_dk_loan' => ($bankloan -> getDieuKien()), 'thu_tuc_loan' => ($bankloan -> getThuTuc()), 'datecreate' => ($bankloan -> getDatecreate()));
	$condition = array('bankloan_id' => ($bankloan -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

function deleteBankLoan($id) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('isavalible' => false);
	$condition = array('bankloan_id' => $id);
	return $con -> update($tbl, $fn, $condition);
}

?>